package com.wg.dome.attribute;

import com.wg.dome.GameConstant;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 属性管理
 */
public class AttributeMgr {
    private final static ConcurrentMap<Long, PlayerAttribute> ATTRIBUT_MAP = new ConcurrentHashMap<>(100);

    /**
     * 获取出战属性
     *
     * @param playerId 玩家ID
     * @param szPos    出战位置 1-6
     * @param updateType 0.不更新 1.更新装备 2.更新英雄
     */
    public static Attribute getFightAttribute(long playerId, byte szPos, int updateType) {
        PlayerAttribute playerAttribute = ATTRIBUT_MAP.computeIfAbsent(playerId, PlayerAttribute::new);
        return playerAttribute.getFightAttribute(szPos, updateType);
    }

    /**
     * 获取出战所有属性
     * @param playerId 玩家ID
     * @return 属性数组
     */
    public static Attribute[] getFightAttributes(long playerId){
        PlayerAttribute playerAttribute = ATTRIBUT_MAP.computeIfAbsent(playerId, PlayerAttribute::new);
        Attribute[] attributes = new Attribute[GameConstant.FIGHT_HERO_NUMBER];
        for (int i=0; i<attributes.length; i++){
            attributes[i] = playerAttribute.getFightAttribute((byte)(i+1), 0);
        }
        return attributes;
    }
}
